package rad.framework.mda.generator.template.main.java.seam;

import java.util.*;
import org.eclipse.uml2.uml.*;
import rad.framework.mda.generator.util.*;
import org.eclipse.emf.codegen.util.*;

public class PageBean
{
  protected static String nl;
  public static synchronized PageBean create(String lineSeparator)
  {
    nl = lineSeparator;
    PageBean result = new PageBean();
    nl = null;
    return result;
  }

  public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl;
  protected final String TEXT_1 = "";
  protected final String TEXT_2 = "/*" + NL + " * ============================================================================" + NL + " *                   GNU Lesser General Public License" + NL + " * ============================================================================" + NL + " */" + NL + "package ";
  protected final String TEXT_3 = ";" + NL;
  protected final String TEXT_4 = NL + NL + "/**" + NL + " * ";
  protected final String TEXT_5 = NL + " *" + NL + " * @author ";
  protected final String TEXT_6 = NL + " * @generated" + NL + " */" + NL + "@Name(\"";
  protected final String TEXT_7 = "Page\")" + NL + "@Scope(ScopeType.CONVERSATION)";
  protected final String TEXT_8 = NL;
  protected final String TEXT_9 = NL + "public class ";
  protected final String TEXT_10 = "PageBean extends AbstractPageBean {" + NL + "" + NL + "\t/** @generated */" + NL + "\tprivate static final String PAGE_FLOW = \"";
  protected final String TEXT_11 = "\";" + NL + "\t/** @generated */" + NL + "\tprivate static final String PAGE = \"";
  protected final String TEXT_12 = "\";" + NL + "\t" + NL + "\t/** @generated */" + NL + "\tpublic ";
  protected final String TEXT_13 = "PageBean() {" + NL + "\t\tsuper(PAGE_FLOW, PAGE);" + NL + "\t}";
  protected final String TEXT_14 = NL + NL + "\t/** @generated */" + NL + "\t@Create" + NL + "\t@Begin(flushMode = FlushModeType.MANUAL)" + NL + "\tpublic void create() {" + NL + "\t\tsuper.create();" + NL + "\t}";
  protected final String TEXT_15 = NL + NL + "\t// --------------------------------------------------------------" + NL + "\t// Page Actions" + NL + "\t// --------------------------------------------------------------";
  protected final String TEXT_16 = NL + NL + "\t/** @generated */" + NL + "\t@Action(prefixes={PAGE_FLOW, PAGE})";
  protected final String TEXT_17 = NL + "\t@End";
  protected final String TEXT_18 = NL + "\t";
  protected final String TEXT_19 = NL + "\tpublic String ";
  protected final String TEXT_20 = "() {";
  protected final String TEXT_21 = NL + "\t\tif (true) {" + NL + "\t\t\treturn \"";
  protected final String TEXT_22 = "\";" + NL + "\t\t}";
  protected final String TEXT_23 = NL + "\t\treturn \"";
  protected final String TEXT_24 = "\";";
  protected final String TEXT_25 = NL + "\t}";
  protected final String TEXT_26 = NL + NL + "\t// --------------------------------------------------------------" + NL + "\t// GoTo Page Navigation Metadata" + NL + "\t// --------------------------------------------------------------" + NL + "" + NL + "\t/** @generated */" + NL + "\tpublic static class ";
  protected final String TEXT_27 = "Menu extends MenuMetadata {" + NL + "" + NL + "\t\tpublic ";
  protected final String TEXT_28 = "Menu(AbstractPageBean component, boolean active, String rendered, String disabled) {" + NL + "\t\t\tsuper(component, PAGE_FLOW, PAGE, active, rendered, disabled);" + NL + "\t\t}" + NL + "\t}";
  protected final String TEXT_29 = NL + NL + "\t/** @generated */" + NL + "\tprivate MenuMetadata ";
  protected final String TEXT_30 = " = new ";
  protected final String TEXT_31 = "Menu(this, ";
  protected final String TEXT_32 = ", null, ";
  protected final String TEXT_33 = ");";
  protected final String TEXT_34 = NL + "}";
  protected final String TEXT_35 = NL;

  public String generate(Object argument)
  {
    final StringBuffer stringBuffer = new StringBuffer();
    

    
State page = (State) argument;
Region flow = (Region)page.getOwner();

    stringBuffer.append(TEXT_1);
    stringBuffer.append(TEXT_2);
    stringBuffer.append(NameHelper.getQualifiedName(flow.getStateMachine()));
    stringBuffer.append(TEXT_3);
    ImportManager importManager = ImportHelper.makeImportManager("");
    importManager.addImport("org.jboss.seam.annotations.Begin");
    importManager.addImport("org.jboss.seam.annotations.End");
    importManager.addImport("org.jboss.seam.annotations.In");
    importManager.addImport("org.jboss.seam.annotations.Out");
    importManager.addImport("org.jboss.seam.annotations.Name");
    importManager.addImport("org.jboss.seam.ScopeType");
    importManager.addImport("org.jboss.seam.annotations.Scope");
    importManager.addImport("org.jboss.seam.annotations.Factory");
    importManager.addImport("rad.framework.seam.AbstractPageBean");
    importManager.addImport("rad.framework.seam.Action");
    
StringBuffer importStringBuffer = stringBuffer;
int importInsertionPoint = stringBuffer.length();
importManager.addCompilationUnitImports(stringBuffer.toString());

    stringBuffer.append(TEXT_4);
    stringBuffer.append(TypeHelper.getDocumentation(page));
    stringBuffer.append(TEXT_5);
    stringBuffer.append(System.getProperty("user.name"));
    stringBuffer.append(TEXT_6);
    stringBuffer.append(NameHelper.removeSpaces(flow.getName()));
    stringBuffer.append(NameHelper.getCapName(page));
    stringBuffer.append(TEXT_7);
    if (StereotypeHelper.hasStereotypes(flow)) {
    stringBuffer.append(TEXT_8);
    stringBuffer.append(StereotypeHelper.getAnnotations(flow));
    }
    stringBuffer.append(TEXT_9);
    stringBuffer.append(NameHelper.getCapName(page));
    stringBuffer.append(TEXT_10);
    stringBuffer.append(NameHelper.removeSpaces(flow.getName()));
    stringBuffer.append(TEXT_11);
    stringBuffer.append(NameHelper.removeSpaces(page.getName()));
    stringBuffer.append(TEXT_12);
    stringBuffer.append(NameHelper.getCapName(page));
    stringBuffer.append(TEXT_13);
    if (page.equals(JsfHelper.getPages(flow).next())) {
    importManager.addImport("org.jboss.seam.annotations.Begin");
    importManager.addImport("org.jboss.seam.annotations.Create");
    importManager.addImport("org.jboss.seam.annotations.FlushModeType");
    stringBuffer.append(TEXT_14);
    }
    stringBuffer.append(TEXT_15);
    for (Iterator<Transition> k=page.getOutgoings().iterator(); k.hasNext();) { Transition t = (Transition)k.next();
    stringBuffer.append(TEXT_16);
    if (JsfHelper.isFinalTransition(flow, t)) {
    stringBuffer.append(TEXT_17);
    }
    if (StereotypeHelper.hasStereotypes(t)) {
    stringBuffer.append(TEXT_18);
    stringBuffer.append(StereotypeHelper.getAnnotations(t));
    }
    stringBuffer.append(TEXT_19);
    stringBuffer.append(NameHelper.removeSpaces(NameHelper.uncapSafeName(t)));
    stringBuffer.append(TEXT_20);
    if (t.getTarget() instanceof Pseudostate && ((Pseudostate)t.getTarget()).getKind().equals(PseudostateKind.CHOICE_LITERAL)) {
    for (Iterator<Transition> l=((Pseudostate)t.getTarget()).getOutgoings().iterator(); k.hasNext();) { Transition t2 = (Transition)l.next();
    stringBuffer.append(TEXT_21);
    stringBuffer.append(NameHelper.removeSpaces(t2.getName()));
    stringBuffer.append(TEXT_22);
    }} else {
    stringBuffer.append(TEXT_23);
    stringBuffer.append(NameHelper.removeSpaces(t.getName()));
    stringBuffer.append(TEXT_24);
    }
    stringBuffer.append(TEXT_25);
    }
    stringBuffer.append(TEXT_26);
    stringBuffer.append(NameHelper.getCapName(page));
    stringBuffer.append(TEXT_27);
    stringBuffer.append(NameHelper.getCapName(page));
    stringBuffer.append(TEXT_28);
    for (Iterator<State> j=JsfHelper.getPages(flow); j.hasNext();) { State item = (State)j.next();
    importManager.addImport(NameHelper.getQualifiedName(flow.getStateMachine()), NameHelper.removeSpaces(item.getName()) + "PageBean." + NameHelper.removeSpaces(item.getName()) + "Menu");
    stringBuffer.append(TEXT_29);
    stringBuffer.append(NameHelper.uncapName(item.getName()));
    stringBuffer.append(TEXT_30);
    stringBuffer.append(NameHelper.removeSpaces(item.getName()));
    stringBuffer.append(TEXT_31);
    stringBuffer.append(page.equals(item) ? true : false);
    stringBuffer.append(TEXT_32);
    stringBuffer.append(page.equals(item) ? "\"#{true}\"" : null);
    stringBuffer.append(TEXT_33);
    }
    stringBuffer.append(TEXT_34);
    importStringBuffer.insert(importInsertionPoint, importManager.computeSortedImports());
    stringBuffer.append(TEXT_35);
    return stringBuffer.toString();
  }
}
